package 剑指Offer.easy;

public class 替换空格 {
    class Solution {
        public String replaceSpace(String s) {
            StringBuilder sb = new StringBuilder();
            char[] chars = s.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == ' ') {
                    sb.append("%20");
                } else {
                    sb.append(chars[i]);
                }
            }
            return sb.toString();
        }
    }

    class Solution2 {
        public String replaceSpace(String s) {
            StringBuilder res = new StringBuilder();
            for(Character c : s.toCharArray())
            {
                if(c == ' ') res.append("%20");
                else res.append(c);
            }
            return res.toString();
        }
    }
}
